﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Excel = Microsoft.Office.Interop.Excel;
using System.Diagnostics;

namespace DimensionAddIn.V2
{
    public class XSheet
    {
        public XTemplate XTemplate { get; set; }
        public string Name { get; set; }
        private XSheetRender _render;

        protected bool IsFirstActive { get; private set; }


        public XSheet()
        {
            IsFirstActive = true;
            _render = new XSheetRender();
        }

        public void Active(Excel.Worksheet worksheet)
        {
            if (IsFirstActive)
            {
                Debug.WriteLine(string.Format("first active : {0}", Name));
                Windows.BusyIndicatorForm busyDlg = new Windows.BusyIndicatorForm();
                busyDlg.ShowMask(() =>
                {
                    OnActive(worksheet); 
                });
                IsFirstActive = false;
            }
        }

        protected void OnActive(Excel.Worksheet worksheet)
        {
            _render.Render(worksheet, XTemplate);
        }
    }
}
